package offer;

import listnode.ListNode;

import java.util.Stack;

public class 从尾到头打印链表06 {

    public int[] reversePrint(ListNode head) {
        Stack<ListNode> integers = new Stack<>();
        //temp
        ListNode temp = head;
        while (temp != null) {
            integers.push(head);
            temp = head.getNext();
        }

        int[] ints = new int[integers.size() - 1];
        for (int i = 0; i < integers.size(); i++) {
            //
            ints[i] = integers.pop().getVal();
        }
        return ints;
    }
}
